﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;

namespace Com.Iooogle.Bms.Controls
{
    /// <summary>
    /// 外部资源加载控件。
    /// </summary>
    [Description("外部资源加载控件 1.0")]
    public class ExternalResourceLoader : System.Web.UI.Control, System.Web.UI.INamingContainer
    {
        private List<String> scripts = new List<string>();

        private List<String> stylesheets = new List<string>();

        /// <summary>
        /// 获取或设置脚本文件虚拟路径。
        /// </summary>
        [Browsable(false)]
        public List<String> Scripts
        {
            get
            {
                return scripts;
            }
            set
            {
                scripts = value;
            }
        }

        /// <summary>
        /// 获取或设置样式表文件虚拟路径。
        /// </summary>
        [Browsable(false)]
        public List<String> Stylesheets
        {
            get
            {
                return stylesheets;
            }
            set
            {
                stylesheets = value;
            }
        }

        /// <summary>
        /// 重写方法。
        /// </summary>
        /// <param name="writer"></param>
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            base.Render(writer);

            HttpContext ctx = HttpContext.Current;

            if (Stylesheets != null)
            {
                foreach (String file in Stylesheets)
                {
                    writer.Write(String.Format(@"<link type=""text/css"" rel=""stylesheet"" href=""{0}{1}"" />", ctx.Request.ApplicationPath, file));
                }
            }

            if (Scripts != null)
            {
                foreach (String file in Scripts)
                {
                    writer.Write(@"<script type=""text/javascript"" src=""{0}{1}""></script>", ctx.Request.ApplicationPath, file);
                }
            }
        }
    }
}
